package xyz.labmem.base.core.result

import cn.hutool.core.date.DateUtil
import io.swagger.annotations.ApiModel
import io.swagger.annotations.ApiModelProperty

/**
 * ResultVo
 * @Author lty
 * @Date 2021/12/15 10:10
 */
@ApiModel("统一对象返回json格式")
open class RV<T>() : RU() {

    @ApiModelProperty(value = "状态码 0:处理成功；-1:处理失败；-2:登录失效；-3权限错误；-11:表单验证失败；")
    var code: Int? = null

    @ApiModelProperty(value = "提示信息")
    var message: String? = null

    @ApiModelProperty(value = "返回时间")
    var timestamp: String = DateUtil.now()

    @ApiModelProperty(value = "返回数据")
    var data: T? = null

    constructor(code: Int?, message: String?, data: T?) : this() {
        this.code = code
        this.message = message
        this.data = data
    }

    fun msg(msg: String): RV<T> {
        message = msg
        return this
    }

    fun code(code: Int): RV<T> {
        this.code = code
        return this
    }

    fun data(data: T): RV<T> {
        this.data = data
        return this
    }

}